<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h2>axios-基地址</h2>
    <button class="get">发送GET</button>
    <button class="post">发送POST</button>
    <script src="./lib/axios.js"></script>
    <script>
        // 配置基地址
        axios.defaults.baseURL='http://ajax-api.itheima.net'

        const base2 = 'http://ajax-api.cn'


        // 测试get请求
        const btn = document.querySelector('.get')
        btn.addEventListener('click', function(){
            // 聊天接口
            axios({
                url:'/api/robot',
                method:'get',
                params:{
                    spoken:'你好吗，我不好'
                }
            }).then(res => {
                console.log(res)
            })
        })

        // 测试post请求
        const postBtn = document.querySelector('.post')

        postBtn.addEventListener('click', function(){
            axios({
                url:'/api/login',
                // 如果还要单独的某个基地址，自己这个请求设置
                baseURL:base2,
                method:'post',
                data:{
                    username:'admin',
                    password:'123456'
                }
            }).then(res => {
                console.log(res)
            })
        })
        
    </script>
</body>
</html>